package han.chensing.latos.maker.windows.dialog.base;

import com.badlogic.gdx.scenes.scene2d.InputEvent;
import com.badlogic.gdx.scenes.scene2d.ui.Skin;
import com.badlogic.gdx.scenes.scene2d.ui.TextButton;
import com.badlogic.gdx.scenes.scene2d.ui.Window;
import com.badlogic.gdx.scenes.scene2d.utils.ClickListener;

import han.chensing.latos.maker.res.Res;
import han.chensing.latos.maker.V;

public class BaseDialog extends Window {

    protected TextButton closeButton;

    public BaseDialog(String title,boolean showCloseButton){
        super(title, Res.get().get("skinBasic",Skin.class));
        Skin skin = Res.get().get("skinBasic", Skin.class);
        if (showCloseButton) {
            closeButton = new TextButton("X", skin);
            getTitleTable().add(closeButton).size(30, 29).padRight(0).padTop(0);
            closeButton.addListener(new ClickListener() {
                @Override
                public void clicked(InputEvent event, float x, float y) {
                    super.clicked(event, x, y);
                    remove();
                }
            });
        }
        setKeepWithinStage(false);
    }

    public BaseDialog(String title) {
        this(title,true);
    }

    public void moveToCenter(){
        setPosition(V.WIDTH/2f-getWidth()/2f,V.HEIGHT/2f-getHeight()/2f);
    }

    public boolean isOnBottom(){
        return getZIndex() != getParent().getChildren().size - 1;
    }
}
